<template>
	<div class="wechat_invest">

112
		<form-page :url.sync="postBank.url"   :rdata.sync="postBank.data"></form-page>

		<com-alert
		:show.sync="alertDialog.show"
		:title.sync="alertDialog.title"
		:buttontxt.sync="alertDialog.buttontxt"
		:content.sync="alertDialog.content"
		></com-alert>
	</div>
</template>

<script>
import FormPage from '../../components/common/form';
import {Api_Tender} from '../../config/api'
import { mapGetters, mapActions } from 'vuex'
import api from '../../data/api';
import ComAlert from '../../components/common/alert'
//import wx from 'weixin-js-sdk'
require('../../config/weixin');

export default {
	data(){
		return{
			postForm:{},
			postBank:{
				url:'', 
				data:{
					RequestData:'',
					transCode:''
				}
			},
			tender:{
				id:'',
				money:''
			}
		}
	},


 
    computed: {
		...mapGetters(['alertDialog'])
	},
	
	components: {
		ComAlert,
		FormPage
	},

	methods:{
		...mapActions([
            'setAlertDialog'
		]),

		getForm(){
			for(var a in this.$children){
				if(this.$children[a].name == 'form')
					this.postForm = this.$children[a];
			}
		},

		async invest(){
			var that = this;


			var data = {'borrow_nid': this.tender.id, 'money': this.tender.money, 'ajax': '1'}
			/* this.$http.post(Api_Tender, data,'').then(function (response) {
				console.log(response)

			}); */

			var res = await api.invest.tender(data);
			if(res.status){
				this.getForm();
				this.postForm.show = true
				this.postBank.url = res.action_url
				this.postBank.data.RequestData = res.RequestData
				this.postBank.data.transCode = res.transCode;	
				//this.postForm.submit();	
			}else{
				this.setAlertDialog({show:true, title:'信息提示', buttontxt:'确定', content:res.msg})
			}



			/* this.postBank.url = 'https://ogws.ghbank.com.cn/extService/ghbExtService.do';
			this.postBank.data.RequestData = '001X11          00000256575122215435D63A843ED1408DC7B56E62F19F7579232FAC94D013E8FDF4ADC35CB4DA4AB82D96A3A400D8BEF941DE498225083B46F534E8D0E426B1376647BE89135E8FC51892676400A87F6E8B660FA4F24E0D0EF4F0A2934FEA5D14B99598D4A491556B079588661C31F5CF36F6EAD00AD375BE5B2D0D8E24077216517339<?xml version="1.0" encoding="UTF-8"?><Document><header><channelCode>P2P027</channelCode><channelFlow>P2P0272018013009411491657282</channelFlow><channelDate>20180130</channelDate><channelTime>114916</channelTime><encryptData></encryptData></header><body><TRANSCODE>OGW00094</TRANSCODE><XMLPARA>MMnRrz4vsWOE6xQ4jMjhopBIgQKcAd8/kGyt6tyQXKvjO/TvpcA2zd6zAmML0eEyNLIfb1JV9FlgeUWWvJ67sEXZaDB6IyPN8jeCBYI2NqV2CV/GB+uIuF/kAtb/UlH5vgAmU2kGQ2Oc1YkI5mu4GQNN7qp6u3Z4Ld4Ct2LhEjtv+ZaxCqN3PZj8Ns9F0tBUsdUDeLOL9tkqPuM55f4jHfi5otTU724KY9EfqJGDoEaqT1xJG+HY4VqoGlBtLDJonZcFv5t75PJQLm4fVVXeRs6TzWwibCs/6jVhghGLHjRlI2HYI+sYfRty9yqdzbMxR5z2OuiEzuD+M67SR2S6XvnraXcaQ8kjgZ/jSeWr0a7s6iS0UBz7qDEPTds6ts9l</XMLPARA></body></Document>';
			this.postBank.data.transCode = 'OGW00094'
			setTimeout(() => {
				that.postForm.submit();	
			}, 5000); */
			
		}
	},

	route: {
		activate ( transition ) {
			transition.next();

			this.tender.id = transition.to.params.id
			this.tender.money = transition.to.params.money

			this.invest();

			// web-view下的页面内
			wx.ready(function() {
				console.log(window.__wxjs_environment === 'miniprogram') // true
			})
		}
	}
}


</script>

<style>

</style>
